<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    nav {
      position: fixed;
      bottom: 0;
      height: 44px;
    }
  </style>
</head>
<body>
  <div id="app">
    <router-view></router-view>
    <nav>
      <router-link to="/">首页</router-link>
      <router-link to="/type">分类</router-link>
      <router-link to="">拼购</router-link>
      <router-link to="">购物车</router-link>
      <router-link to="">个人</router-link>
    </nav>

  </div>
  <script src="./vue.js"></script>
  <script src="./vue-router.js"></script>
  <script>
    const type = {
      template: `
        <div>
          <div class="left">
            <router-link :to="'/type/rm?index=' + index" v-for="(type, index) in goodses.types" :key="index">{{type}}</router-link>
          </div>
          <div class="right">
            <router-view></router-view>  
          </div>
        </div>
      `,
      data () {
        return {
          goodses: {
            types: [
              '热门推荐1', '热门推荐2', '热门推荐3', '热门推荐4'
            ],
            
          }
        }
      }
    }
    
    const childType = {
      template: `
        <div>
          <div v-for="i in item">{{i.title}}</div>  
        </div>
      `, 
      watch: {
        '$route': {
          handler (to) {
            const index = to.query.index
            this.item = this.items[index]
          } 
        }
      },  
      data () {
        return {
          item: [],
          items: [
            [
              {title: '手机1', img: ''},
              {title: '手机1', img: ''},
              {title: '手机1', img: ''},
              {title: '手机1', img: ''},
              {title: '手机1', img: ''},
              {title: '手机1', img: ''},

            ],[
              {title: '手机2', img: ''},
              {title: '手机', img: ''},
              {title: '手机', img: ''},
              {title: '手机', img: ''},
              {title: '手机', img: ''},
              {title: '手机', img: ''},

            ],[
              {title: '手机3', img: ''},
              {title: '手机', img: ''},
              {title: '手机', img: ''},
              {title: '手机', img: ''},
              {title: '手机', img: ''},
              {title: '手机', img: ''},

            ],[
              {title: '手机4', img: ''},
              {title: '手机', img: ''},
              {title: '手机', img: ''},
              {title: '手机', img: ''},
              {title: '手机', img: ''},
              {title: '手机', img: ''},

            ]
          ]
        }
      },
      created () {
        console.log(this.$route.query.index)
      }
    }
    const routes = [
      {
        path: '/',
      }, {
        path: '/type',
        component: type,
        children: [
          {
            path: 'rm',
            component: childType
          }
        ]
      }
    ]

    const router = new VueRouter({
      routes
    })

    const app = new Vue({
      el: "#app",
      router,
      data: {},
    })


  </script>
</body>
</html>